package com.itheima.order.web;


import com.itheima.feign.client.UserClient;
import com.itheima.feign.pojo.User;
import com.itheima.order.pojo.Order;
import com.itheima.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 29143
 */
@RestController
@RequestMapping("/order")
public class OrderWeb {

    @Autowired
    private OrderService orderService;

    @Autowired
    private UserClient userClient;


    @GetMapping("{id}")
    public Order findAllById(@PathVariable("id") Long id){

        //根据id查询订单并返回
        Order order = orderService.findAllById(id);

        //根据关联的userId远程查询用户信息
        User user = userClient.fiandById(order.getUserId());
        //将用户信息设置到订单种
        order.setUser(user);

        return order;
    }

}